package com.kehutong.charge.admin;

import com.kehutong.charge.entity.PayBillManages;
import com.kehutong.charge.entity.ReceiptsStatistics;
import com.kehutong.charge.service.PayManagesService;
import com.kehutong.common.PageUtils;
import com.kehutong.common.util.Token;
import org.coraframework.authz.HasPermission;
import org.coraframework.inject.Inject;
import org.coraframework.json.JSONObject;
import org.coraframework.mvc.MvcAction;
import org.coraframework.mvc.http.Bean;
import org.coraframework.mvc.http.ReqMapping;
import org.coraframework.mvc.http.result.Result;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * @program: kht
 * @description: 票据管理-缴费功能
 * @author: jian Ye
 * @create: 2021/8/3
 **/
@MvcAction
@ReqMapping("/admin/pay/charge/bill/payment")
public class PayManagesController {

    @Inject
    PayManagesService payManagesService;


    @ReqMapping("/page")
    @HasPermission("crm:charge:payment:view")
    public Object page(JSONObject jsonObject) {
        return payManagesService.findPage(jsonObject);
    }


    @ReqMapping("/list")
    @HasPermission("crm:charge:payment:view")
    public Object list(JSONObject jsonObject) {
        return payManagesService.findList(jsonObject);
    }


    @Bean(newInstance=true, copy=true)
    @HasPermission("crm:charge:payment:edit")
    @ReqMapping("/save")
    public Object save(PayBillManages entity, Token token){
        return payManagesService.save(entity, token);
    }


    @Bean(copy=true)
    @HasPermission("crm:charge:payment:edit")
    @ReqMapping("/update")
    public Object update(PayBillManages entity) throws Exception {
        return payManagesService.update(entity);
    }


    @HasPermission("crm:charge:payment:edit")
    @ReqMapping("/delete")
    public Object delete(PayBillManages entity) {
        return payManagesService.deleteById(entity.getId());
    }


    @ReqMapping("/setStatus")
    @HasPermission("crm:charge:payment:edit")
    public Object setStatus(PayBillManages entity) throws Exception {
        entity.setStatus(!entity.isStatus());
        payManagesService.update(entity);
        return Result.success();
    }


    @ReqMapping("/get")
    public Object get(PayBillManages entity) {
        return Result.success(entity);
    }


    /**
     * 统计功能
     */
    @ReqMapping("/statistPage")
    @HasPermission("crm:charge:payment:view")
    public Object receiptStat(JSONObject jsonObject){
        List<ReceiptsStatistics> listObj = payManagesService.groupData(jsonObject);
        return PageUtils.buildPage(jsonObject,listObj);
    }


    @ReqMapping("/payPage")
    @HasPermission("crm:charge:payment:view")
    public Object payPage(JSONObject jsonObject) {
        return payManagesService.findPayPage(jsonObject);
    }


    @ReqMapping("/payPage/export")
    @HasPermission("crm:charge:payment:view")
    public void payPageExport(HttpServletRequest req, HttpServletResponse resp, JSONObject jsonObject) {
        payManagesService.payPageExport(req,resp,jsonObject);
    }

}
